﻿using System;
using System.Collections.Generic;
using Helpers;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.LogEntries
{
	// Token: 0x020002CC RID: 716
	public class ChangeSettlementOwnerLogEntry : LogEntry, IEncyclopediaLog, IWarLog
	{
		// Token: 0x06002A32 RID: 10802 RVA: 0x000B47D5 File Offset: 0x000B29D5
		internal static void AutoGeneratedStaticCollectObjectsChangeSettlementOwnerLogEntry(object o, List<object> collectedObjects)
		{
			((ChangeSettlementOwnerLogEntry)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x06002A33 RID: 10803 RVA: 0x000B47E3 File Offset: 0x000B29E3
		protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
		{
			base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			collectedObjects.Add(this.Settlement);
			collectedObjects.Add(this.PreviousClan);
			collectedObjects.Add(this.NewClan);
		}

		// Token: 0x06002A34 RID: 10804 RVA: 0x000B4810 File Offset: 0x000B2A10
		internal static object AutoGeneratedGetMemberValueSettlement(object o)
		{
			return ((ChangeSettlementOwnerLogEntry)o).Settlement;
		}

		// Token: 0x06002A35 RID: 10805 RVA: 0x000B481D File Offset: 0x000B2A1D
		internal static object AutoGeneratedGetMemberValuePreviousClan(object o)
		{
			return ((ChangeSettlementOwnerLogEntry)o).PreviousClan;
		}

		// Token: 0x06002A36 RID: 10806 RVA: 0x000B482A File Offset: 0x000B2A2A
		internal static object AutoGeneratedGetMemberValueNewClan(object o)
		{
			return ((ChangeSettlementOwnerLogEntry)o).NewClan;
		}

		// Token: 0x06002A37 RID: 10807 RVA: 0x000B4837 File Offset: 0x000B2A37
		internal static object AutoGeneratedGetMemberValue_bySiege(object o)
		{
			return ((ChangeSettlementOwnerLogEntry)o)._bySiege;
		}

		// Token: 0x06002A38 RID: 10808 RVA: 0x000B4849 File Offset: 0x000B2A49
		public ChangeSettlementOwnerLogEntry(Settlement settlement, Hero newOwner, Hero previousOwner, bool bySiege)
		{
			this.Settlement = settlement;
			this.PreviousClan = previousOwner.Clan;
			this.NewClan = newOwner.Clan;
			this._bySiege = bySiege;
		}

		// Token: 0x06002A39 RID: 10809 RVA: 0x000B4878 File Offset: 0x000B2A78
		public override ImportanceEnum GetImportanceForClan(Clan clan)
		{
			if (this.PreviousClan == this.NewClan)
			{
				return ImportanceEnum.Zero;
			}
			if (this.NewClan != clan)
			{
				return ImportanceEnum.Important;
			}
			return ImportanceEnum.VeryImportant;
		}

		// Token: 0x06002A3A RID: 10810 RVA: 0x000B4898 File Offset: 0x000B2A98
		public bool IsRelatedToWar(StanceLink stance, out IFaction effector, out IFaction effected)
		{
			IFaction faction = stance.Faction1;
			IFaction faction2 = stance.Faction2;
			effector = this.NewClan.MapFaction;
			effected = this.PreviousClan.MapFaction;
			return (this.NewClan.MapFaction == faction && this.PreviousClan.MapFaction == faction2) || (this.NewClan.MapFaction == faction2 && this.PreviousClan.MapFaction == faction);
		}

		// Token: 0x06002A3B RID: 10811 RVA: 0x000B4909 File Offset: 0x000B2B09
		public override void GetConversationScoreAndComment(Hero talkTroop, bool findString, out string comment, out ImportanceEnum score)
		{
			score = ImportanceEnum.Zero;
			comment = "";
			if (this._bySiege && (this.NewClan == Clan.PlayerClan || this.PreviousClan == Clan.PlayerClan))
			{
				score = ImportanceEnum.Important;
				if (findString)
				{
					comment = "str_comment_changeownerofsettlement_you_captured_castle";
				}
			}
		}

		// Token: 0x06002A3C RID: 10812 RVA: 0x000B4948 File Offset: 0x000B2B48
		public override int GetAsRumor(Settlement talkSettlement, ref TextObject comment)
		{
			int result = 0;
			Settlement settlement = this.Settlement;
			float num;
			if (this.NewClan.IsBanditFaction && settlement.IsHideout && Campaign.Current.Models.MapDistanceModel.GetDistance(talkSettlement, settlement, 60f, out num))
			{
				comment = new TextObject("{=MXGtQ6YV}I hear {.%}{BANDIT_NAME}{.%} have moved into the old {HIDEOUT_NAME} near here. Travellers better watch themselves.", null);
				comment.SetTextVariable("BANDIT_NAME", this.NewClan.Name);
				comment.SetTextVariable("HIDEOUT_NAME", settlement.Name);
				return 4;
			}
			if (this._bySiege && this.PreviousClan == talkSettlement.MapFaction)
			{
				comment = new TextObject("{=UMn2QMIk}Did you hear {ENEMY_NAME} took {FORTRESS_NAME} by storm? Do you think they'll come here next?", null);
				comment.SetTextVariable("ENEMY_NAME", FactionHelper.GetTermUsedByOtherFaction(this.NewClan, talkSettlement.MapFaction, false));
				comment.SetTextVariable("FORTRESS_NAME", settlement.Name);
				return 10;
			}
			return result;
		}

		// Token: 0x06002A3D RID: 10813 RVA: 0x000B4A25 File Offset: 0x000B2C25
		public override string ToString()
		{
			return this.GetEncyclopediaText().ToString();
		}

		// Token: 0x06002A3E RID: 10814 RVA: 0x000B4A32 File Offset: 0x000B2C32
		public bool IsVisibleInEncyclopediaPageOf<T>(T obj) where T : MBObjectBase
		{
			return (obj == this.Settlement || obj == this.NewClan || obj == this.NewClan.Leader) && !this._bySiege;
		}

		// Token: 0x06002A3F RID: 10815 RVA: 0x000B4A70 File Offset: 0x000B2C70
		public TextObject GetEncyclopediaText()
		{
			TextObject textObject = GameTexts.FindText("str_settlement_owner_changed_news", null);
			textObject.SetTextVariable("SETTLEMENT", this.Settlement.IsHideout ? this.Settlement.Name : this.Settlement.EncyclopediaLinkWithName);
			if (this.NewClan == null && this.Settlement.IsHideout)
			{
				return GameTexts.FindText("str_hideout_owner_changed_news", null);
			}
			StringHelpers.SetCharacterProperties("LORD", this.NewClan.Leader.CharacterObject, textObject, false);
			return textObject;
		}

		// Token: 0x04000CB0 RID: 3248
		[SaveableField(80)]
		public readonly Settlement Settlement;

		// Token: 0x04000CB1 RID: 3249
		[SaveableField(81)]
		public readonly Clan PreviousClan;

		// Token: 0x04000CB2 RID: 3250
		[SaveableField(82)]
		public readonly Clan NewClan;

		// Token: 0x04000CB3 RID: 3251
		[SaveableField(83)]
		private readonly bool _bySiege;
	}
}
